﻿using Base.ClientUI;
using Base.WCS.Entity;

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.Windows.Documents;
using System.Windows.Forms;

namespace GK.WCS.Client
{
    public partial class FrmPlate : UITitlePage
    {
        public FrmPlate()
        {
            InitializeComponent();
            timer1.Start();
        }

        void myLoad()
        {
            List<SysParam> paramList = HttpParam.getParam();
            if (paramList == null)
            {
                this.ShowErrorTip("网络不稳定!");
                return;
            }
            foreach (SysParam p in paramList)
            {
                if (p.id == 11)
                {
                    txtFavoriteConfig1.Text = p.v + "";
                }
            }

        }

        int getLast()
        {
            List<SysParam> paramList = HttpParam.getParam();
            if (paramList == null)
            {
                this.ShowErrorTip("网络不稳定!");
                return 0;
            }
            foreach (SysParam p in paramList)
            {
                if (p.id == 11)
                {
                    return p.v;
                }
            }
            return 0;
        }

        private void btnFavoriteConfig1_Click(object sender, EventArgs e)
        {
            String t = boxCount.Text;
            int c = int.Parse(t);
            int begin = int.Parse(txtFavoriteConfig1.Text);

            int before = getLast();
            if (before == 0)
            {
                this.ShowErrorTip("条码验证失败!");
                return;
            }
            if (begin < before)
            {
                this.ShowErrorTip("条码可能已经存在!");
                return;
            }
            int end = c + begin;
            int repeat = int.Parse(boxRepeat.Text);
            for (; begin < end; begin++)
            {
                for (int i = 0; i < repeat; i++)
                {
                    HttpPrint.printCode1(begin);
                }
            }
            HttpParam.updateValue(11, end);
            txtFavoriteConfig1.Text = end+"";
        }
        public override void Init()
        {
            base.Init();
            myLoad();
        }

        private void ShowMessage(bool result)
        {
            if (result)
            {
                this.ShowSuccessTip("操作成功!");
            }
            else
            {
                this.ShowErrorTip("操作失败!");
            }
        }






        private void uiSymbolButton1_Click(object sender, EventArgs e)
        {
            this.ShowSuccessTip(HttpTaskUtil.move(srcTextBox.Text, desTextBox.Text));

        }

        private void uiSymbolButton2_Click(object sender, EventArgs e)
        {
            int code = int.Parse(uiTextBox1.Text);
            int before = getLast();
            if (before == 0)
            {
                this.ShowErrorTip("条码验证失败!");
                return;
            }
            if (before <= code)
            {
                this.ShowErrorTip("条码未生成过!");
            }
            HttpPrint.printCode1(code);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            return;
            List<SysParam> paramList = HttpParam.getParam();
            if (paramList == null)
            {
                //this.ShowErrorTip("网络不稳定!");
                return;
            }
            foreach (SysParam p in paramList)
            {
                if (p.id == 11)
                {
                    txtFavoriteConfig1.Text = p.v + "";
                }
                if (p.id == 101)
                {
                    uiSwitch1.Active = p.v == 2 ? true : false;
                }
                if (p.id == 102)
                {
                    uiSwitch2.Active = p.v == 2 ? true : false;
                }
            }
        }

        private void uiSwitch1_ValueChanged(object sender, bool value)
        {
            if (uiSwitch1.Active)
            {
                HttpParam.updateValue(101, 2);
            }
            else
            {
                HttpParam.updateValue(101, 1);
            }
        }

        private void uiSwitch2_ValueChanged(object sender, bool value)
        {
            if (uiSwitch2.Active)
            {
                HttpParam.updateValue(102, 2);
            }
            else
            {
                HttpParam.updateValue(102, 1);
            }
        }
    }
}
